import { defineResponseResolver } from '~~/mocks/define';

import db from '~/DB';
import { validateToken } from '~~/mocks/middleware/token';
import { getUser } from '~~/mocks/utils/user';
import { getUserMenus } from '~~/mocks/utils/menu';

export default validateToken(async (req, res, ctx) => {
  const user = await getUser(req);
  if (!user) {
    return res(ctx.status(404), ctx.json({}));
  }
  const menus = await getUserMenus(req);
  return res(
    ctx.json({
      ...user,
      password: undefined,
      menus: menus,
    }),
  );
});
